<h2><%= t('.challenge_signups.enter', :default => "Sign Up For %{title}", :title => @collection.title) %></h2>

<!-- note for FRONT END
The fields in the form frequently wrap around to a second line. 
So if anyone can think of a better design for this, that would be awesome
-->

<!-- descriptions-->
<!-- /descriptions-->
<!--subnavigation, sorting and actions-->
<!--/subnav-->

<!--main content-->
<%= form_for([@collection, @challenge_signup], :url => (edit_record ? collection_signup_path(@collection) : collection_signups_path(@collection))) do |signup_form| %>
  <%= error_messages_for @challenge_signup %>

  <fieldset class="preface profile">
  	<legend>General Information</legend>
  	<h3>General Information</h3>
    <% if @challenge.signup_instructions_general %>
      <%=raw sanitize_field(@challenge, :signup_instructions_general) %>
    <% end %>
   	<% if signup_form.object.new_record? && current_user.pseuds.size > 1 %>
      <dl>
        <dt><%= signup_form.label :pseud_id, t("prompt.pseud", :default => "Select pseudonym: ") %></dt>
        <dd><%= signup_form.select :pseud_id, options_from_collection_for_select(current_user.pseuds, :id, :name, current_user.default_pseud.id) %></dd>
      </dl>
    <% else %>
      <p><%= signup_form.hidden_field :pseud_id, :value => (signup_form.object.new_record? ? current_user.default_pseud.id : signup_form.object.pseud.id) %></p>
    <% end %>  
  </fieldset>

  <% %w(requests offers).each do |prompt_type| %>
  <fieldset class="preface profile">
  	<legend><%= prompt_type.capitalize %></legend>
  	<h3>
  	  <%= prompt_type.capitalize %> 
  	  (<%= @challenge.send("#{prompt_type}_num_required") %>
  	  <% if @challenge.send("#{prompt_type}_num_required") != @challenge.send("#{prompt_type}_num_allowed") %>
  	    - <%= @challenge.send("#{prompt_type}_num_allowed") %><% end %>)
  	</h3>
    <% if @challenge.send("signup_instructions_#{prompt_type}") %>
      <%=raw sanitize_field(@challenge, "signup_instructions_#{prompt_type}".to_sym) %>
    <% end %>
    <% if @challenge_signup.send("#{prompt_type}").empty? %>
  	  <% 1.upto(@challenge.send("#{prompt_type}_num_required")) do %>
        <% @challenge_signup.send("#{prompt_type}").build %>
      <% end %>
    <% end %>
    <% @challenge_signup.send("#{prompt_type}").each_with_index do |prompt, index| %>
      <%= signup_form.fields_for prompt_type.to_sym, prompt do |prompt_form| %>
        <%= render :partial => "prompts/prompt_form", 
            :locals => {:form => prompt_form, :is_offer => (prompt_type == "offers"), :index => index, 
                        :required => (index < @challenge.send("#{prompt_type}_num_required"))} %>
      <% end %>
    <% end %>
    
    <% if @challenge.send("#{prompt_type}_num_allowed") > @challenge.send("#{prompt_type}_num_required") %>
      <p class="navigation">
        <%= link_to_add_section(
             ts("Add another %{type}? (Up to %{allowed} allowed.)", :type => prompt_type.singularize, :allowed => @challenge.send("#{prompt_type}_num_allowed")), 
             signup_form, prompt_type.to_sym, "prompts/prompt_form", {:is_offer => (prompt_type == "offers"), :required => false}) 
        %>
      </p>
    <% end %>

  </fieldset>
  <% end # requests & offers section %>

  <fieldset>
  	<legend><%h= 'Submit' %></legend> 
    <p class="submit">
      <%= signup_form.submit 'Submit' %>
    </p>
  </fieldset>

<% end %>

<!--/content-->

<!--subnav-->
<ul class="navigation" role="navigation">
<li><%= link_to 'Back', @collection %></li>
</ul>
<!--/subnav-->
